package com.qidian.mes.sys.controller;

import com.qidian.mes.sys.service.DictionaryService;
import com.qidianit.mes.common.pojo.MesResult;
import com.qidianit.mes.pojo.Dictionary;
import com.qidianit.mes.pojo.DictionaryItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2025/7/25 9:39
 * @description
 */
@RestController
@CrossOrigin
@RequestMapping("/dict")
public class DictionaryController {

    @Autowired
    private DictionaryService dictionaryService;

    @GetMapping("/list")
    public MesResult<List<Dictionary>> list(){
        return dictionaryService.queryAll();
    }

    @GetMapping("/listItemByDictCode")
    public MesResult<List<DictionaryItem>> listItemByDictCode(String dictCode){
        return dictionaryService.queryByDictCode(dictCode);
    }

    @PostMapping
    public MesResult<Boolean> add(@RequestBody Dictionary dictionary){
        return MesResult.success(dictionaryService.save(dictionary));
    }
    @PutMapping
    public MesResult<Boolean> update(@RequestBody Dictionary dictionary){
        return MesResult.success(dictionaryService.updateById(dictionary));
    }
    @DeleteMapping
    public MesResult<Boolean> delete(Integer id){
        return MesResult.success(dictionaryService.removeById(id));
    }

}
